#include "Bookmark.h"
#include "BookmarkManager.h"

namespace Bookmarks {

QIcon Bookmark::__bookmarkIcon;

Bookmark::Bookmark(const QString &fileName, int lineNumber, BookmarkManager *manager)
    : ITextMark()
    , _manager(manager)
    , _fileName(fileName)
    , _lineNumber(lineNumber)
{
}

QIcon Bookmark::icon() const
{
    if (__bookmarkIcon.isNull())
        __bookmarkIcon = QIcon(":/bookmark");
    return __bookmarkIcon;
}

void Bookmark::updateLineNumber(int lineNumber)
{
    if (lineNumber != _lineNumber) {
        _lineNumber = lineNumber;
        _manager->updateBookmark(this);
    }
}

void Bookmark::updateBlock(const QTextBlock &block)
{
    if (_lineText != block.text()) {
        _lineText = block.text();
        _manager->updateBookmark(this);
    }
}

void Bookmark::removeFromEditor()
{
    _manager->removeBookmark(this);
}

void Bookmark::documentClosing()
{
    // todo: impl
}

} // namespace Bookmarks
